package com.gigalaxy.game.card.phom.utils
{

	public class PhomArray extends Array
	{
		public function PhomArray(... parameters)
		{
			super(parameters);
		}

		public function removeByValue(value:Object):PhomArray
		{
			for (var i = 0; i < this.length; i++)
			{
				if (this[i] == value)
				{
					this.splice(i, 1);
					break;
				}
			}

			return this;
		}

		public function addAll(anotherArr:Array):PhomArray
		{
			for (var i = 0; i < anotherArr.length; i++)
			{
				this.push(anotherArr[i]);
			}

			return this;
		}

		public function removeAll(anotherArr:Array):PhomArray
		{
			for (var i = 0; i < anotherArr.length; i++)
			{
				this.removeByValue(anotherArr[i]);
			}

			return this;
		}

		public function powerSet(arr:Array):Array
		{
			var ps = new Array(new Array());

			for (var i = 0; i < arr.length; i++)
			{
				// we modify the ps array in the next loop,
				// so can't use the ps.length property directly in the loop condition.
				var current_length = ps.length;
				for (var j = 0; j < current_length; j++)
				{
					ps.push(ps[j].concat(arr[i]));
				}
			}

			return ps;
		}
	}
}
